package com.lingjtx.iot.network.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lingjtx.common.thread.commom.ApiKeyFilter;
import com.lingjtx.common.thread.commom.NettyServerExceptionResolver;
import com.lingjtx.common.thread.commom.RestResponseConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class IotNetworkConfig {

    @Bean
    public ApiKeyFilter apiKeyFilter() {
        return new ApiKeyFilter();
    }

    @Bean
    @Primary
    @ConditionalOnMissingBean(ObjectMapper.class)
    public ObjectMapper jacksonObjectMapper(RestResponseConfig config) {
        return config.jacksonObjectMapper();
    }

    @Bean
    public NettyServerExceptionResolver resolver() {
        return new NettyServerExceptionResolver();
    }
}
